# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libid3tag
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.16.3
pkgrel=1
pkgdesc="Library for id3 tagging (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.underbit.com/products/mad/"
msys2_repository_url="https://codeberg.org/tenacityteam/libid3tag"
msys2_references=(
  "cpe: cpe:/a:libid3tag_project:libid3tag"
  "cpe: cpe:/a:media-libs:libid3tag"
  "cpe: cpe:/a:underbit:libid3tag"
)
license=("spdx:GPL-2.0-or-later")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gperf")
source=("${_realname}-${pkgver}.tar.gz::https://codeberg.org/tenacityteam/libid3tag/archive/${pkgver}.tar.gz")
sha256sums=('0561009778513a95d91dac33cee8418d6622f710450a7cb56a74636d53b588cb')

prepare() {
  mv "${_realname}" "${_realname}-${pkgver}"
  cd "${_realname}-${pkgver}"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DCMAKE_DLL_NAME_WITH_SOVERSION=ON \
      -DBUILD_SHARED_LIBS=ON \
      ../${_realname}-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .
}
